<template>
  <div class="control-box">
    <div class="btn flexCenter">
      <div
        class="flexCenter"
        :class="{active:currentBtn.id}"
        v-for="(item,index) in btnList"
        :key="index"
        @click="currentBtn = item"
      >{{item.name}}</div>
    </div>
    <div class="number">
      <div
        @click="clickEventWin(item)"
        class="flexCenter fontSize16 ash"
        :class="{blue:currentWin.id===item.id}"
        :key="index"
        v-for="(item,index) in windowList"
      >{{item.name}}</div>
    </div>
    <div class="tables" v-if="currentBtn.id==='yzw'">
      <div v-for="(item,index) in dataList" :key="index" @click="setPreview(item)">
        <span class="iconfont iconshexiangtou"></span>
        <div>
          <div :title="item.yzwmc" class="fontSize16">{{item.yzwmc | ellipsis}}</div>
          <span class="iconfont iconshishixiaoxitixing"></span>
        </div>
      </div>
    </div>
    <div class="ytkz centerbox" v-if="currentBtn.id==='ytkz'">
      <ytkz @setControl="setControl"  />
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import ytkz from "./ytkz.vue";

@Component({
  filters: {
    //超过20位显示 ...
    ellipsis: function (value) {
      if (!value) return "未命名";
      if (value.length > 10) {
        return value.slice(0, 10) + "...";
      }
      return value;
    },
  },
  components: {
    ytkz,
  },
})
export default class extends Vue {
  @Prop()
  dialogData;
  currentBtn = {
    name: "预位置",
    id: "yzw",
  };
  btnList = [
    {
      name: "预位置",
      id: "yzw",
    },
    {
      name: "云台控制",
      id: "ytkz",
    },
  ];
  currentWin = {
    name: "1",
    id: "1",
  };
  windowList = [
    {
      name: "1",
      layout: 1,
      id: "1",
    },
    {
      name: "4",
      layout: 2,
      id: "4",
    },
  ];
  dataList = [];
  @Watch("dialogData", { immediate: true })
  fetch() {
    let bayId = this.dialogData.jgid;
    console.log(this.dialogData);
    console.log(bayId);
    if (bayId) {
      let data = {
        bayId,
      };
      (this as any).$services
        .getEquipmentVideo({ data })
        .then((result) => {
          let data = result.data || [];

          console.log(data);
          this.dataList = data;
        })
        .catch((err: object) => {
          console.log(err);
        });
    }
  }
  clickEventWin(item) {
    this.currentWin = item;
    this.$emit("clickEventWin", item);
  }
    // 设置云台控制
  setControl(id) {
    this.$emit("setControl", id);
  }
    // 设置播放数据
  setPreview(item) {
    this.$emit("setPreview", item);
  }
}
</script>

<style lang="scss" scoped>
.control-box {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 0.1rem 0 0.1rem 0.15rem;
  display: flex;
  flex-wrap: wrap;
  .btn {
    width: 2rem;
    height: 0.3rem;
    border: 2px solid #129ee4;
    border-radius: 0.2rem;
    overflow: hidden;
    > div {
      flex: 1;
      height: 100%;
      cursor: pointer;
    }
    .active {
      background-color: #0069af;
    }
  }
  .number {
    width: calc(100% - 2rem);
    height: 0.3rem;
    box-sizing: border-box;
    padding: 0 0.1rem;
    display: flex;
    > div {
      width: 0.3rem;
      height: 0.3rem;
      border-radius: 50%;
      margin: 0 0.15rem;
      cursor: pointer;
    }
    .ash {
      background-color: #7f787f;
    }
    .blue {
      background-color: #7acbf8;
    }
  }
  .tables {
    width: 100%;
    height: calc(100% - 0.4rem);
    margin-top: 0.1rem;
    overflow-y: auto;
    > div {
      height: 0.3rem;
      width: 100%;
      display: flex;
      align-items: center;
      margin: 0.1rem 0;
      > .iconfont {
        font-size: 0.34rem;
      }
      > div {
        margin-left: 0.1rem;
        flex: 1;
        height: 100%;
        background-color: rgba(27, 86, 184, 0.4);
        display: flex;
        justify-content: space-between;
        align-items: center;
        box-sizing: border-box;
        padding-left: 0.1rem;
        > .iconfont {
          margin-right: 0.1rem;
          font-size: 0.28rem;
        }
      }
    }
  }
  .ytkz {
    width: 100%;
    height: calc(100% - 0.4rem);
    margin-top: 0.1rem;
  }
  .fontSize16 {
    font-size: 0.16rem;
  }
  .flexCenter {
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
</style>

